package com.shibida.shibidaProject.userInfo.dao;

import com.shibida.shibidaProject.userInfo.domain.UserVO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface UserInfoRepository extends JpaRepository<UserVO, Integer> {
    @Query(value = "select count(id) from t_user_base where sex=:sex1", nativeQuery = true)
    int queryCount(String sex1);

    // 使用原生的sql
    @Query(value = "select * from t_user_base where sex=:sex1 order by id limit :startRow, :limitNum", nativeQuery = true)
    List<UserVO> queryBySex(String sex1, int startRow, int limitNum);

    @Query(value = "select * from t_user_base", nativeQuery = true)
    List<UserVO> queryAll();    
    @Query(value = "select * from t_user_base limit :_start, :_limit", nativeQuery = true)
    List<UserVO> queryPageAll(int _start, int _limit);
    //获取用户信息
    @Query(value = "select * from t_user_base where user_name=:username",nativeQuery = true)
    UserVO Match(String username);
    //通过用户名查找
    @Query(value = "select * from t_user_base WHERE user_name LIKE %:username%",nativeQuery = true)
    List<UserVO> queryAllByUserName(String username);
    //通过地址查找
    @Query(value = "select * from t_user_base WHERE locate LIKE %:locate%",nativeQuery = true)
    List<UserVO> queryAllByLocate(String locate);
    @Query(value = "select * from t_user_base WHERE id=:id",nativeQuery = true)
    UserVO queryAllById(int id);
    @Transactional
    @Modifying
    @Query(value = "UPDATE `t_user_base` SET `user_name` = :userName, `tel` = :tel, `sex` = :sex, `age` = :age, `head_icon_url` = :headIconUrl, `locate` = :locate, `id_card` = :idCard, `tags` = :tags WHERE id = :id", nativeQuery = true)
    void updateAllById(String userName, String sex, int age,String tel, String headIconUrl, String locate, String idCard, String tags, int id);
}
